﻿using System;
using System.Linq;
using System.Net.Sockets;
using System.Xml;

namespace 日期和
{
    class Program
    {
        static void Main(string[] args)
        {
            //日期
            DateTime dt = DateTime.Now;

            Console.WriteLine("现在是{0}年",dt.Year);
            Console.WriteLine("现在是{0}年,{1}月",dt.Year,dt.Month);
            Console.WriteLine("现在是{0}年,{1}月,{2}日",dt.Year,dt.Month,dt.Day);


            //Length
            string str = Console.ReadLine();
            Console.WriteLine("字符串的长度为:"+ str.Length);
            Console.WriteLine("字符串中第一个字符为:"+str[0]);
            Console.WriteLine("字符串中最后一个字符为:"+str[str.Length-1]);

            string str1 = Console.ReadLine();
            for (int i = str1.Length - 1; i >= 0; i--)
            {
                    Console.WriteLine(str1[i]);
             }

            //IndexOf和LastIndexOf
            string str2 = Console.ReadLine();
            if (str2.IndexOf("@")== -1)
            {
                Console.WriteLine("字符串中没有@");
            }
            else
            {
                Console.WriteLine("字符串中有@,出现的位置是:{0}",str2.IndexOf("@")+1);
            }

            string str3 = Console.ReadLine();
            int First = str3.IndexOf("@");
            int Last = str3.LastIndexOf("@");
            if (First != -1)
            {
                if (First == Last)
                {
                    Console.WriteLine("在此字符串中仅有一个@");
                }
                else
                {
                    Console.WriteLine("此字符串中有多个@");
                }
            }
            else
            {
                Console.WriteLine("字符串中没哟@");
            }

            //Replace：字符串替换函
            string str4 = Console.ReadLine();
            if(str4.IndexOf(",")!=-1)
            {
                str4 = str4.Replace(",", "~");
            }


            // Substring：字符串截取函数
            string str5 = Console.ReadLine();
            int First1 = str5.IndexOf("@");
            str5 = str5.Substring(0, First1);
            Console.WriteLine("邮箱中的用户名是:"+str5);

            //insert 插入字符串
            string str6 = Console.ReadLine();
            str = str.Insert(1, "@@@");
            Console.WriteLine("新字符串为：" + str);

            //替换
            string re = Console.ReadLine();
            re = re.Replace(",", ".");
            Console.WriteLine(re);

            Console.WriteLine("请输入你的证件号：");
            string man = Console.ReadLine();
            Console.WriteLine("你的出生年月为：");
            man = man.Substring(6,8);
            Console.WriteLine(man);


        }
    }
}
